package com.cn.wanxi.service.impl;

import com.cn.wanxi.dao.ProductDao;
import com.cn.wanxi.dao.UserDao;
import com.cn.wanxi.dao.impl.ProductImpl;
import com.cn.wanxi.dao.impl.UserImpl;
import com.cn.wanxi.model.ProductModel;
import com.cn.wanxi.model.ResultModel;
import com.cn.wanxi.model.UserModel;
import com.cn.wanxi.service.ProductService;
import com.cn.wanxi.util.Result;

import java.util.List;

public class ProductServiceImpl implements ProductService {
    @Override
    public ResultModel findAll(ProductModel productModel) {
//        ResultModel resultModel = new ResultModel();
        ProductDao productDao = new ProductImpl();
        List<ProductModel> list = productDao.findAll(productModel);
//        resultModel.setCode(Result.SUCCESS_CODE);
//        resultModel.setData(list);
//        return resultModel;
        int count=productDao.getCount(productModel);
        return new ResultModel("", 0, count, list);
    }

    @Override
    public ResultModel add(ProductModel model) {
        ProductDao productDao = new ProductImpl();
        int count=productDao.add(model);
        return new ResultModel("",0,count,null);
    }

    @Override
    public ResultModel findById(ProductModel productModel) {
        ResultModel resultModel = new ResultModel();
        ProductDao productDao = new ProductImpl();
        ProductModel model = productDao.findById(productModel);
        resultModel.setData(model);
        return resultModel;
    }

    @Override
    public ResultModel update(ProductModel model) {
        return null;
    }

    @Override
    public ResultModel delete(ProductModel model) {
        ResultModel resultModel = new ResultModel();
        ProductDao productDao = new ProductImpl();
        int count = productDao.delete(model);
        if (count > 0) {
            resultModel.setMsg("success");
        } else {
            resultModel.setMsg("error");
        }
        return resultModel;
    }

    @Override
    public ResultModel getCount(ProductModel model) {
        return null;
    }


}
